﻿using Org.BouncyCastle.Asn1.X509;
using Serilog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Controls;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Models;
using 低频天线阵列相控阵信号发生系统SmartFASK12.View;

namespace 低频天线阵列相控阵信号发生系统SmartFASK12
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            MTiming.Singleton().StartTime();

            InitializeComponent();

            //以下表示在程序运行目录 以天为单位生成日志文件(也可以以小时等为单位)
            Log.Logger = new LoggerConfiguration()
               .MinimumLevel.Debug()
               .WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day)
               .CreateLogger();

            Init();

            MTiming.Singleton().StopTime();
            TimeSpan timeSpan = MTiming.Singleton().Result();
        }

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            // 隐藏选择卡
            tabControl1.TabPages[4].Parent = null;
            tabControl1.TabPages[6].Parent = null;

            tabPage1.Controls.Add(new UCommunicationDistanceTest() { Dock = DockStyle.Fill });
            tabPage2.Controls.Add(new UMagneticFieldTest() { Dock = DockStyle.Fill });
            tabPage3.Controls.Add(new USystem() { Dock = DockStyle.Fill });
            tabPage4.Controls.Add(new UFrequencyBandTesting() { Dock = DockStyle.Fill });
            tabPage5.Controls.Add(new UDataAcquisition() { Dock = DockStyle.Fill });
            tabPage8.Controls.Add(new USmartFASK12() { Dock = DockStyle.Fill });
            tabPage7.Controls.Add(new USmartDPRO20() { Dock = DockStyle.Fill });
            View.AdjustDemodulation.Form1 form1 = new View.AdjustDemodulation.Form1
            {
                //设置窗体没有边框，加入到选项卡中
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false,
                //form1.Parent = ((TabControl)sender).SelectedTab;
                ControlBox = false,
                Dock = DockStyle.Fill
            };
            form1.Show();
            tabPage6.Controls.Add(form1);
            if (!File.Exists(MPublic.ConfigFilePath))
            {
                //_configModel = new ConfigModel();
            }
            else
            {

            }

            //初始化FFT计算
            Thread thread = new Thread(InitFFT_MATLAB)
            {
                IsBackground = true
            };
            thread.Start();
        }

        /// <summary>
        /// 初始化_MATLAB计算程序
        /// </summary>
        private void InitFFT_MATLAB()
        {
            MyMatlab.FFTre(new List<double>()
            {
                1
            });
        }

    }
}
